package com.jxau.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.jxau.util.enums.ResponseCode;

public class Responses<T> {
    //    响应编码
    private String code;
    // 响应消息
    private String msg;
    //响应体
    private T result;
    //总页数
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private Integer pageNum;
    public Responses(ResponseCode code, String msg, T result, Integer pageNum) {
        this.code = code.getCode();
        this.msg = msg;
        this.result = result;
        this.pageNum = pageNum;
    }
    public Responses(ResponseCode code, String msg, T result) {
        this.code = code.getCode();
        this.msg = msg;
        this.result = result;
    }

    public Responses(ResponseCode code, String msg) {
        this.code = code.getCode();
        this.msg = msg;
    }

    public Responses(ResponseCode code) {
        this.code = code.getCode();
    }

    public static <T>Responses success(){
        return new Responses(ResponseCode.SUCCESS,"",null);
    }

    public static <T>Responses success(String msg){
        return new Responses(ResponseCode.SUCCESS,msg,null);
    }

    public static <T>Responses success(T result){
        return new Responses(ResponseCode.SUCCESS,"",result);
    }
    public static <T>Responses success(String msg,T result){
        return new Responses(ResponseCode.SUCCESS,msg,result);
    }
    public static <T>Responses success(String msg,T result, Integer pageNum){
        return new Responses(ResponseCode.SUCCESS,msg,result,pageNum);
    }
    public static <T>Responses error(){
        return new Responses(ResponseCode.ERROR,"",null);
    }

    public static <T>Responses error(String msg){
        return new Responses(ResponseCode.ERROR,msg,null);
    }

    public static <T>Responses error(T result){
        return new Responses(ResponseCode.ERROR,"",result);
    }
    public static <T>Responses error(String msg,T result){
        return new Responses(ResponseCode.ERROR,msg,result);
    }
    public static <T>Responses error(String msg,T result,Integer pageNum){
        return new Responses(ResponseCode.ERROR,msg,result,pageNum);
    }
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }
}
